#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define MAX 100
typedef struct{
	char name[MAX];
	int arriveTime;
	int startTime;
	int serviceTime;
	int finishTime;
	int zzTime;
	double dqzzTime;
	int count;
}PCB;
void RR(int r,int n){
	PCB p[MAX];
	int i,j;
	printf("name\tarriveTime\tserviceTime:\n");
	for(i=0;i<n;i++)
	scanf("%s%d%d",&p[i].name,&p[i].arriveTime,&p[i].serviceTime);
	for(i=0;i<n;i++)
	for(j=i+1;j<n;j++)
	if(p[i].arriveTime>p[j].arriveTime){
		PCB temp;
		temp=p[i];
		p[i]=p[j];
		p[j]=temp;
	}
	if(n==1){
		p[0].startTime=p[0].arriveTime;
		if(r>=p[0].serviceTime){
			p[0].finishTime=p[0].startTime+p[0].serviceTime;
			p[0].zzTime=p[0].finishTime-p[0].arriveTime;
			p[0].dqzzTime=p[0].zzTime*1.0/p[0].serviceTime;
			p[0].count++;
		}
		else{
			while(p[0].serviceTime-p[0].count*r>r){
				p[0].startTime=p[0].finishTime;
				p[0].finishTime=p[0].startTime+r;
				p[0].count++;
			}
				p[0].startTime=p[0].finishTime;
				p[0].finishTime=p[0].finishTime+(p[0].serviceTime-p[0].count*r);
				p[0].count++;
			p[0].zzTime=p[0].finishTime-p[0].arriveTime;
			p[0].dqzzTime=p[0].zzTime*1.0/p[0].serviceTime;
		}
	}
	else{
		p[0].startTime=p[0].arriveTime;
		if(r>=p[0].serviceTime){
			int finishTimesum;
			p[0].finishTime=p[0].startTime+p[0].serviceTime;
			finishTimesum=p[0].finishTime;
			p[0].zzTime=p[0].finishTime-p[0].arriveTime;
			p[0].dqzzTime=p[0].zzTime*1.0/p[0].serviceTime;
			p[0].count++;
			int sum;
			for(i=1;i<n;i++){
				if(r>=p[i].serviceTime){
					p[i].startTime=finishTimesum;
					p[i].finishTime=p[i].startTime+p[i].serviceTime;
					finishTimesum=p[i].finishTime;
					p[i].zzTime=p[i].finishTime-p[i].arriveTime;
					p[i].dqzzTime=p[i].zzTime*1.0/p[i].serviceTime;
					p[i].count++;
				}
				else{
					p[i].startTime=finishTimesum;
					p[i].finishTime=p[i].startTime+r;
					finishTimesum=p[i].finishTime;
					p[i].zzTime=p[i].finishTime-p[i].arriveTime;
					p[i].dqzzTime=p[i].zzTime*1.0/p[i].serviceTime;
					p[i].count++;
				}
				int s=0;
				for(j=1;j<n;j++){
					if(p[j].serviceTime-p[j].count*r<=0){
						s++;
					}
				}
				sum=s;
		}
		if(sum<n-1){
				for(j=1;j<n;j++){
					if(p[j].serviceTime-p[j].count*r>=r){
						p[j].startTime=finishTimesum;
						p[j].finishTime=p[j].startTime+r;
						finishTimesum=p[j].finishTime;
						p[j].zzTime=p[j].finishTime-p[j].arriveTime;
						p[j].dqzzTime=p[j].zzTime*1.0/p[j].serviceTime;
						p[j].count++;
					}
					else if(p[j].serviceTime-p[j].count*r<r&&p[j].serviceTime-p[j].count*r>0){
						p[j].startTime=finishTimesum;
						p[j].finishTime=p[j].startTime+(p[j].serviceTime-p[j].count*r);
						finishTimesum=p[j].finishTime;
						p[j].zzTime=p[j].finishTime-p[j].arriveTime;
						p[j].dqzzTime=p[j].zzTime*1.0/p[j].serviceTime;
						p[j].count++;
					}
					int s=0;
					int k;
					for(k=1;k<n;k++){
						if(p[k].serviceTime-p[k].count*r<=0){
							s++;
						}
					}
					if(s<n-1){
						if(j==n-1){
							j=0;
						}
					}
					else
					break;
				}
			}
	}
	else{
		int finishTimesum;
		p[0].finishTime=p[0].startTime+r;
		finishTimesum=p[0].finishTime;
		p[0].zzTime=p[0].finishTime-p[0].arriveTime;
		p[0].dqzzTime=p[0].zzTime*1.0/p[0].serviceTime;
		p[0].count++;
		for(i=1;i<n;i++){
			if(r>=p[i].serviceTime){
				p[i].startTime=finishTimesum;
				p[i].finishTime=p[i].startTime+p[i].serviceTime;
				finishTimesum=p[i].finishTime;
				p[i].zzTime=p[i].finishTime-p[i].arriveTime;
				p[i].dqzzTime=p[i].zzTime*1.0/p[i].serviceTime;
				p[i].count++;
			}
			else{
				p[i].startTime=finishTimesum;
				p[i].finishTime=p[i].startTime+r;
				finishTimesum=p[i].finishTime;
				p[i].zzTime=p[i].finishTime-p[i].arriveTime;
				p[i].dqzzTime=p[i].zzTime*1.0/p[i].serviceTime;
				p[i].count++;
			}
		}
			for(j=0;j<n;j++){
				if(p[j].serviceTime-p[j].count*r>=r){
					p[j].startTime=finishTimesum;
					p[j].finishTime=p[j].startTime+r;
					finishTimesum=p[j].finishTime;
					p[j].zzTime=p[j].finishTime-p[j].arriveTime;
					p[j].dqzzTime=p[j].zzTime*1.0/p[j].serviceTime;
					p[j].count++;
				}
				else if(p[j].serviceTime-p[j].count*r<r&&p[j].serviceTime-p[j].count*r>0){
					p[j].startTime=finishTimesum;
					p[j].finishTime=p[j].startTime+(p[j].serviceTime-p[j].count*r);
					finishTimesum=p[j].finishTime;
					p[j].zzTime=p[j].finishTime-p[j].arriveTime;
					p[j].dqzzTime=p[j].zzTime*1.0/p[j].serviceTime;
					p[j].count++;
				}
				int s=0;
				int k;
				for(k=0;k<n;k++){
					if(p[k].serviceTime-p[k].count*r<=0){
						s++;
					}
				}
				if(s<n){
					if(j==n-1){
						j=-1;
					}
				}
				else
				break;
			}
	}
}
	printf("name\tarriveTime\tstartTime\tserviceTime\tfinishTime\tzzTime\tdqzzTime\tcount\n");
	for(i=0;i<n;i++)
	printf("%s\t%d\t%d\t%d\t%d\t%d\t%.2f\t%d\n",p[i].name,p[i].arriveTime,p[i].startTime,p[i].serviceTime,p[i].finishTime,p[i].zzTime,p[i].dqzzTime,p[i].count);
}
int main(){
	int r,n;
	printf("r:");
	scanf("%d",&r);
	printf("n:");
	scanf("%d",&n);
	RR(r,n);
	return 0;
}
